#ifndef TCPC_TIMER_H_INCLUDED
#define TCPC_TIMER_H_INCLUDED

#include "common.h"

enum {
#if 1
	PD_TIMER_DISCOVER_ID = 0,
	PD_TIMER_BIST_CONT_MODE,
	PD_TIMER_NO_RESPONSE,
	PD_TIMER_PS_HARD_RESET,
	PD_TIMER_PS_SOURCE_OFF,
	PD_TIMER_PS_SOURCE_ON,
	PD_TIMER_PS_TRANSITION,
	PD_TIMER_SENDER_RESPONSE,
	PD_TIMER_SINK_REQUEST,
	PD_TIMER_SINK_WAIT_CAP,
	PD_TIMER_SOURCE_CAPABILITY,
	PD_TIMER_SOURCE_START,
	PD_TIMER_VCONN_ON,
#if CONFIG_USB_PD_VCONN_STABLE_DELAY
	PD_TIMER_VCONN_STABLE,
#endif	/* CONFIG_USB_PD_VCONN_STABLE_DELAY */
	PD_TIMER_VDM_MODE_ENTRY,
	PD_TIMER_VDM_MODE_EXIT,
	PD_TIMER_VDM_RESPONSE,
	PD_TIMER_SOURCE_TRANSITION,
	PD_TIMER_SOURCE_SWAP_STANDBY,
	PD_TIMER_SRC_RECOVER,
#if CONFIG_USB_PD_REV30
	PD_TIMER_CK_NOT_SUPPORTED,
	PD_TIMER_SINK_TX,
#if CONFIG_USB_PD_REV30_PPS_SOURCE
	PD_TIMER_SOURCE_PPS_TIMEOUT,
#endif	/* CONFIG_USB_PD_REV30_PPS_SOURCE */
#endif	/* CONFIG_USB_PD_REV30 */
	PD_TIMER_HARD_RESET_SAFE0V,
	PD_TIMER_HARD_RESET_SAFE5V,

/* PD_TIMER (out of spec) */
#if CONFIG_USB_PD_SAFE0V_DELAY
	PD_TIMER_VSAFE0V_DELAY,
#endif	/* CONFIG_USB_PD_SAFE0V_DELAY */
#if CONFIG_USB_PD_SAFE0V_TIMEOUT
	PD_TIMER_VSAFE0V_TOUT,
#endif	/* CONFIG_USB_PD_SAFE0V_TIMEOUT */
#if CONFIG_USB_PD_SAFE5V_DELAY
	PD_TIMER_VSAFE5V_DELAY,
#endif	/* CONFIG_USB_PD_SAFE5V_DELAY */
#if CONFIG_USB_PD_RETRY_CRC_DISCARD
	PD_TIMER_DISCARD,
#endif	/* CONFIG_USB_PD_RETRY_CRC_DISCARD */
#if CONFIG_USB_PD_VBUS_STABLE_TOUT
	PD_TIMER_VBUS_STABLE,
#endif	/* CONFIG_USB_PD_VBUS_STABLE_TOUT */
	PD_TIMER_CVDM_RESPONSE,
	PD_TIMER_DFP_FLOW_DELAY,
	PD_TIMER_UFP_FLOW_DELAY,
	PD_TIMER_VCONN_READY,
	PD_PE_VDM_POSTPONE,
#if CONFIG_USB_PD_REV30
	PD_TIMER_DEFERRED_EVT,
#if CONFIG_USB_PD_REV30_SNK_FLOW_DELAY_STARTUP
	PD_TIMER_SNK_FLOW_DELAY,
#endif	/* CONFIG_USB_PD_REV30_SNK_FLOW_DELAY_STARTUP */
#if CONFIG_USB_PD_REV30_PPS_SINK
	PD_TIMER_PPS_REQUEST,
#endif	/* CONFIG_USB_PD_REV30_PPS_SINK */
#endif	/* CONFIG_USB_PD_REV30 */
	PD_TIMER_PE_IDLE_TOUT,
	PD_PE_TIMER_END_ID,
#endif /* CONFIG_USB_POWER_DELIVERY */

/* TYPEC_RT_TIMER (out of spec) */
#if 1
	TYPEC_RT_TIMER_START_ID = PD_PE_TIMER_END_ID,
#else
	TYPEC_RT_TIMER_START_ID = 0,
#endif	/* CONFIG_USB_POWER_DELIVERY */
	TYPEC_RT_TIMER_SAFE0V_DELAY = TYPEC_RT_TIMER_START_ID,
	TYPEC_RT_TIMER_SAFE0V_TOUT,
	TYPEC_RT_TIMER_ROLE_SWAP_START,
	TYPEC_RT_TIMER_ROLE_SWAP_STOP,
	TYPEC_RT_TIMER_STATE_CHANGE,
	TYPEC_RT_TIMER_DISCHARGE,
	TYPEC_RT_TIMER_LOW_POWER_MODE,
#if 1
	TYPEC_RT_TIMER_PE_IDLE,
#if CONFIG_USB_PD_WAIT_BC12
	TYPEC_RT_TIMER_PD_WAIT_BC12,
#endif /* CONFIG_USB_PD_WAIT_BC12 */
#endif	/* CONFIG_USB_POWER_DELIVERY */
#if CONFIG_WATER_DETECTION
	TYPEC_RT_TIMER_WD_IN_KPOC,
#endif /* CONFIG_WATER_DETECTION */
	TYPEC_TIMER_ERROR_RECOVERY,

/* TYPEC_TRY_TIMER */
	TYPEC_TRY_TIMER_START_ID,
	TYPEC_TRY_TIMER_DRP_TRY = TYPEC_TRY_TIMER_START_ID,
/* TYPEC_DEBOUNCE_TIMER */
	TYPEC_TIMER_START_ID,
	TYPEC_TIMER_CCDEBOUNCE = TYPEC_TIMER_START_ID,
	TYPEC_TIMER_PDDEBOUNCE,
	TYPEC_TIMER_TRYCCDEBOUNCE,
	TYPEC_TIMER_SRCDISCONNECT,
	TYPEC_TIMER_DRP_SRC_TOGGLE,

/* TYPEC_TIMER (out of spec) */
#if CONFIG_TYPEC_CAP_NORP_SRC
	TYPEC_TIMER_NORP_SRC,
#endif	/* CONFIG_TYPEC_CAP_NORP_SRC */
	PD_TIMER_NR,
};

void tcpc_enable_lpm_timer(struct sgm41620_tcpc *tcpc, bool en);
bool tcpc_is_timer_active(struct sgm41620_tcpc *tcpc, int start, int end);
void tcpc_enable_timer(struct sgm41620_tcpc *tcpc, uint32_t timer_id);
void tcpc_disable_timer(struct sgm41620_tcpc *tcpc, uint32_t timer_id);
void tcpc_restart_timer(struct sgm41620_tcpc *tcpc, uint32_t timer_id);
void tcpc_reset_pe_timer(struct sgm41620_tcpc *tcpc);
void tcpc_reset_typec_debounce_timer(struct sgm41620_tcpc *tcpc);
void tcpc_reset_typec_try_timer(struct sgm41620_tcpc *tcpc);
int tcpci_timer_init(struct sgm41620_tcpc *tcpc);
int tcpci_timer_deinit(struct sgm41620_tcpc *tcpc);
void on_pe_timer_timeout(struct sgm41620_tcpc *tcpc, uint32_t timer_id);
#endif /* TCPC_TIMER_H_INCLUDED */
